"""
支付宝
https://opendocs.alipay.com/open/02ekfp?scene=32
微信
https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=5_1
"""


def identify_pay_code_type(pay_code):
    typ = None
    try:
        pay_code_len = len(pay_code)
        pay_code_s2 = int(pay_code[0:2])
        if 10 <= pay_code_s2 <= 15:
            if pay_code_len == 18:
                typ = {'name': '微信', 'code': 1}
        elif 25 <= pay_code_s2 <= 30:
            if 16 <= pay_code_len <= 24:
                typ = {'name': '支付宝', 'code': 2}
    except Exception as e:
        print(e)
    return typ


def get_pay_code_type(pay_code):
    return identify_pay_code_type(str(pay_code))


# 识别错误，重试一次，错误码：827876320448055431
def get_pay_code_type2(pay_code):
    pay_code = str(pay_code)
    typ = identify_pay_code_type(pay_code)
    fixed = False
    if typ is None:
        pay_code = pay_code[::-1]
        fixed = True
        typ = identify_pay_code_type(pay_code)
    if typ is not None:
        typ.update({'pay_code': pay_code, 'fixed': fixed})
    return typ
